package com.aifast.system.sys.controller;

import com.aifast.common.annotations.AiIdempotent;
import com.aifast.common.base.Controller;

import com.aifast.common.base.R;
import com.aifast.common.layui.LayuiDataTable;
import com.aifast.system.sys.entity.SysOrg;
import com.aifast.system.sys.service.SysOrgService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 机构表 前端控制器
 * </p>
 *
 * @author fujian
 * @since 2022-01-07
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/sysOrg")
public class SysOrgController extends Controller {

    private final SysOrgService service;

//    @SaCheckPermission("org:list")
    @GetMapping("list")
    public LayuiDataTable list() {
        return service.list(get("name"),getInt("type"), getPage());
    }

    @AiIdempotent
//    @SaCheckPermission("org:addOrUpdate")
    @PostMapping("add")
    public R add(SysOrg sysOrg) {
        return service.insertOrUpdate(sysOrg) ? OK() : ERROR();
    }

//    @SaCheckPermission("org:list")
    @GetMapping("info")
    public R info() {
        return OK(service.info(getInt("id")));
    }

    @AiIdempotent
//    @SaCheckPermission("org:del")
    @GetMapping("del")
    public R del() {
        return service.del(getInt("id"), get("ids")) ? OK() : ERROR();
    }

    @GetMapping("all")
    public R all(){
        return OK(service.all());
    }

    @GetMapping("selectData")
    public R selectData(){
        return OK(service.selectData());
    }

}

